
///// ColoredParagraphs /////
    using System;
    using System.Collections.Generic;
    using System.Collections;
    //using System.Linq;
    using System.Text;
    using System.IO;
    using iTextSharp.text;
    using iTextSharp.text.pdf;


namespace ColoredParagraphs
{
    class Program
    {
        static void Main(string[] args)
        {
            // Generates a PDF file using different color spaces for text.
            // 
            // @param args:  no arguments needed here

            Console.WriteLine("Chapter 11: example ColoredParagraphs");
            Console.WriteLine("-> Creates a PDF file with paragraph that are written in special colors.");
            Console.WriteLine("-> extra resource needed: foxdog.jpg (chapter 5)");
            Console.WriteLine("-> file generated: colored_paragraphs.pdf");
            // step 1: creation of a document-object
            Document document = new Document();
            try
            {
                // step 2:
                // we create a writer
                PdfWriter writer = PdfWriter.GetInstance(
                    // that listens to the document
                        document,
                    // and directs a PDF-stream to a file
                        new FileStream("colored_paragraphs.pdf", FileMode.Create));
                // step 3: we open the document
                document.Open();
                // step 4:
                PdfContentByte cb = writer.DirectContent;

                PdfSpotColor psc_cmyk = new PdfSpotColor("iTextSpotColorCMYK", new CMYKColor(0.3f, .9f, .3f, .1f));
                SpotColor sc_cmyk = new SpotColor(psc_cmyk, 0.5f);

                Image img = Image.GetInstance(@"D:\Temp\DD.jpg");
                PdfPatternPainter img_pattern = cb.CreatePattern(img.ScaledWidth, img.ScaledHeight, img.ScaledWidth, img.ScaledHeight);
                img_pattern.AddImage(img, img.ScaledWidth, 0f, 0f, img.ScaledHeight, 0f, 0f);
                img_pattern.SetPatternMatrix(1f, 0f, 0f, 1f, 60f, 60f);
                PatternColor img_color = new PatternColor(img_pattern);

                PdfShading axial = PdfShading.SimpleAxial(writer, 36, 716, 396, 788, BaseColor.ORANGE, BaseColor.BLUE);
                PdfShadingPattern axialPattern = new PdfShadingPattern(axial);
                ShadingColor axialColor = new ShadingColor(axialPattern);

                document.Add(new Paragraph("This is a paragraph painted using a SpotColor", new Font(Font.NORMAL, 24, Font.BOLD, sc_cmyk)));
                document.Add(new Paragraph("This is a paragraph painted using an image pattern", new Font(Font.NORMAL, 24, Font.BOLD, img_color)));
                document.Add(new Paragraph("This is a paragraph painted using a shading pattern", new Font(Font.NORMAL, 24, Font.BOLD, axialColor)));
            }

            catch (DocumentException de)
            {
                Console.Error.WriteLine(de.Message);
            }

            catch (IOException ioe)
            {
                Console.Error.WriteLine(ioe.Message);
            }

            // step 5: we close the document
            document.Close();

            Console.ReadLine();
        }
    }
}
